package com.mq.ps.topic;

import com.mq.config.ConnectUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.TimeoutException;

/**
 * @author hezhaoxiang
 * @Deprecated //订阅模型 topic 生产者
 * @date 20:35 2020/9/7
 **/
public class HelloWorldSend {

    //路由名称
    private final static String EXCHANGE_NAME ="TOPIC_EXCHANGE_NAME";

    public static  void sendMsg() throws URISyntaxException, KeyManagementException, TimeoutException, NoSuchAlgorithmException, IOException {
        //1. 获取连接
        Connection connect = ConnectUtils.getConnect();
        //2. 获取信道
        Channel channel = connect.createChannel();
        //3. 声明路由
        channel.exchangeDeclare(EXCHANGE_NAME,"topic",true);
        //4. 发布消息
        String msg = "TOPIC_MSG";
        // 5.传输的 key
        String key = "INSERT.One.Two";
        channel.basicPublish(EXCHANGE_NAME,key, MessageProperties.PERSISTENT_TEXT_PLAIN,msg.getBytes());
        //5. 关闭信道
        channel.close();
        //6. 关闭连接
        connect.close();
    }

    public static void main(String[] args) throws KeyManagementException, TimeoutException, NoSuchAlgorithmException, IOException, URISyntaxException {
        HelloWorldSend.sendMsg();
    }
}
